﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BuffImage : MonoBehaviour
{
    private BuffInfo buffInfo;
    public CanvasGroup details;
    public Text BuffType;
    public Text BuffEffect;
    public Text BuffDuration;
    public Image image;
    public Sprite Slow, EarnMoney, LevelUp1, LevelUp2, Burn, CatchGoalSlow;
    // Start is called before the first frame update
    void Start()
    {
        details.alpha = 0;
    }

    // Update is called once per frame
    void Update()
    {
        switch ((ConstOfBuff.BuffType)buffInfo.buffIndex)
        {
            case ConstOfBuff.BuffType.Slow:
                BuffType.text = "减速";
                BuffEffect.text = "强度：" + buffInfo.effect;
                image.sprite = Slow;
                break;
            case ConstOfBuff.BuffType.EarnMoney:
                BuffType.text = "生产";
                BuffEffect.text = "单位生产：" + buffInfo.effect;
                image.sprite = EarnMoney;
                break;
            case ConstOfBuff.BuffType.LevelUp:
                BuffType.text = "升级";
                BuffEffect.text = "等级：+" + buffInfo.effect;
                if(buffInfo.effect ==1)
                {
                    image.sprite = LevelUp1;
                }
                else
                {
                    image.sprite = LevelUp2;
                }
                break;
            case ConstOfBuff.BuffType.Burn:
                BuffType.text = "灼伤";
                BuffEffect.text = "每秒受伤：" + buffInfo.effect;
                image.sprite = Burn;
                break;
            case ConstOfBuff.BuffType.CatchGoalSlow:
                BuffType.text = "效果：搬运";
                BuffEffect.text = "无法攻击";
                image.sprite = CatchGoalSlow;
                break;
            case ConstOfBuff.BuffType.RepeatableAttackIncrease:
                BuffType.text = "攻击力增加";
                BuffEffect.text = "增加：" + buffInfo.effect;
                image.sprite = Burn;
                break;
            case ConstOfBuff.BuffType.RepeatableMaxHpIncrease:
                BuffType.text = "体力上限增加";
                BuffEffect.text = "增加：" + buffInfo.effect;
                break;
            default:
                break;
        }
        if (buffInfo.duration == -1)
        {
            BuffDuration.text = "剩余时间：" + "∞";
        }
        else
            BuffDuration.text = "剩余时间：" + System.Math.Round(buffInfo.duration) + "s";
    }

    public void setBuff(BuffInfo info)
    {
        buffInfo = info;
    }

    public void onEnter()
    {
        details.alpha = 1;
    }

    public void onExit()
    {
        details.alpha = 0;
    }
}
